package com.hc.homestay.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.homestay.commons.ResultMap;
import com.hc.homestay.mapper.ToStaffMapper;
import com.hc.homestay.pojo.ToGuestHome;
import com.hc.homestay.pojo.ToStaff;
import com.hc.homestay.service.ToStaffService;

@Service
public class ToStaffServiceimpl implements ToStaffService {

	/* @Autowired */

	@Resource
	private ToStaffMapper toSalffMapper;

	@Override
	public ResultMap<ToStaff> findToStaffList(Map<String,Object> paramMap) {
		int pageNo = 1; 
		int pageSize = 5;
		 if(paramMap.get("pageNo")!=null && !"".equals(paramMap.get("pageNo"))) {
			pageNo = Integer.valueOf(paramMap.get("pageNo").toString());
		}
		if(paramMap.get("pageSize")!=null && !"".equals(paramMap.get("pageSize"))) {
			pageSize = Integer.valueOf(paramMap.get("pageSize").toString());
		} 
		/* 设置分页 */
		PageHelper.startPage(pageNo,pageSize);
		
		//调用查询方法
		List<ToStaff> ListLayui =  toSalffMapper.findToStaffList(paramMap);
		/* 使用分页插件的PageInfo类，获取分页信息 */
		PageInfo<ToStaff> pages = new PageInfo<>(ListLayui);
		return new ResultMap<ToStaff>(ListLayui,(int)pages.getTotal());
	}

	@Override
	public Integer deleteToStaffByid(Integer id) { 
		// TODO Auto-generated method stub
		return toSalffMapper.deleteById(id);
	}

	@Override
	public Integer updatetoSalff(ToStaff toStaff) {
		UpdateWrapper<ToStaff> updateWrapper  = new UpdateWrapper<ToStaff>();
		updateWrapper.eq("S_id",toStaff.getsId());   
		return toSalffMapper.update(toStaff, updateWrapper );
	}

	@Override
	public ToStaff getLogin(ToStaff toStaff) {
		return toSalffMapper.getLogin(toStaff);
	}

}